from time import sleep

from selenium.webdriver.common.by import By

from service.login import Login
from util.Util import BoxDriver,BasePage

class Addgroup(BasePage):

    def dingwei(self):
        self.driver.click(By.XPATH, '//*[@id="s-menu-superadmin"]/button')
        self.driver.switch_to_frame_index(0)

    def addgroup(self):
        self.dingwei()
        # 添加成员
        self.driver.click(By.LINK_TEXT, '添加应用')
        self.driver.click(By.LINK_TEXT, "分组")
        self.driver.input(By.ID, "children[]","分组1") 
        self.driver.input(By.CSS_SELECTOR, ".form-group:nth-child(2) #children\\[\\]","分组2")
        self.driver.input(By.CSS_SELECTOR, ".form-group:nth-child(3) #children\\[\\]","分组3")
        self.driver.input(By.CSS_SELECTOR, ".form-group:nth-child(4) #children\\[\\]","分组4")
        self.driver.input(By.CSS_SELECTOR, ".form-group:nth-child(5) #children\\[\\]","分组5")
        self.driver.click(By.ID, "submit")

        self.delgroup()

    def delgroup(self):
        # 前置条件，定位到分组
        self.driver.click(By.LINK_TEXT, "分组")
        try:
            while True:
                sleep(2)
                self.driver.click(By.XPATH,'//*[@id="categoryList"]/div[1]/div/span')
                self.driver.alert_accept()
        except Exception as e:
            print("删除完成！")

if __name__ == '__main__':
    driver = BoxDriver('Chrome')
    Login(driver).login('admin', '123456')
    Addgroup(driver).addgroup()
